package com.bdqn.controller;

import com.bdqn.pojo.BackendUser;
import com.bdqn.pojo.User;
import com.bdqn.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class UserController {

    @Autowired
    public UserService userService;

    /*开发者用户登录界面*/
    @RequestMapping("/dev/login")
    public String devlogin(){
        return "devlogin";
    }
   /*后台登录界面*/
    @RequestMapping("/manager/login")
    public String managerlogin(){
        return "managerlogin";
    }
    /*开发者主界面*/
    @RequestMapping("/dev/index")
    public String devindex(){
        return "devindex";
    }
    /*后台主界面*/
    @RequestMapping("/manager/index")
    public String managerindex(){
        return "managerindex";
    }
    /*前台登录验证*/
    @RequestMapping("/dev/yan")
    public String devyan(User user, HttpServletRequest request){
        User pan=userService.devlogin(user);
        if (pan!=null){
            request.getSession().setAttribute("devuser",pan);
            return "devindex";
        }
        else{
            return "devlogin";
        }

    }
    /*后台登录验证*/
    @RequestMapping("/manager/yan")
    public String manageryan(BackendUser backendUser, HttpServletRequest request){
        BackendUser pan=userService.backUser(backendUser);
        if (pan!=null){
            request.getSession().setAttribute("backuser",pan);
            return "managerindex";
        }
        else{
            return "managerlogin";
        }
    }
    /*前台注销*/
    @RequestMapping("/dev/logout")
    public String devlogout(HttpServletRequest request){
            request.getSession().removeAttribute("devuser");
            return "devlogin";
    }
    /*后台注销*/
    @RequestMapping("/manager/logout")
    public String managerlogin(HttpServletRequest request){
        request.getSession().removeAttribute("backuser");
        return "managerlogin";
    }


}
